package cn.sunxyz.aop.proxy;

import java.util.function.Supplier;

/**
 * Created by yangrd on 2017/5/25.
 */
class ProxyManger {

    public static <T> T getProxy(Singleton singleton) {
        return (T) singleton.getProxy();
    }

    public static <T> T getProxy(Crate crate) {
        return (T) crate.getProxy();
    }

    public enum Singleton {
        ADVICE_PROXY(new AdviceProxy()),
        HANDLER_PROXY(new HandlerProxy());
        private Proxy proxy;

        Singleton(Proxy proxy) {
            this.proxy = proxy;
        }

        private Proxy getProxy() {
            return proxy;
        }
    }

    public enum Crate {
        ADVICE_PROXY(() -> new AdviceProxy()),
        HANDLER_PROXY(() -> new HandlerProxy());
        private Supplier<Proxy> supplier;

        Crate(Supplier<Proxy> supplier) {
            this.supplier = supplier;
        }

        private Proxy getProxy() {
            return supplier.get();
        }
    }

}
